package com.usc.mock.log.bean;

import com.usc.mock.log.config.AppConfig;
import com.usc.mock.log.enums.DisplayType;
import com.usc.mock.log.enums.ItemType;
import com.usc.mock.log.enums.PageId;
import com.usc.mock.utlil.RandomBox;
import com.usc.mock.utlil.RandomNum;
import com.usc.mock.utlil.RandomNumBuilder;
import com.usc.mock.utlil.RandomNumString;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class AppPage {

     PageId last_page_id;

     PageId page_id;

     ItemType item_type;

     String item;

     Integer during_time;

     String extend1;

     String extend2;

     DisplayType source_type;

     String refer_id;




     public static  AppPage build(AppCommon appCommon,PageId pageId,PageId lastPageId,Integer duringTime){



          ItemType itemType=null;
          String item=null;
          String extend1=null;
          String extend2=null;
          DisplayType sourceType=null;
          String referId=null;


          RandomBox<DisplayType> sourceTypeGroup =   RandomBox.<DisplayType>builder().add(DisplayType.query, AppConfig.sourceTypeRate[0])
                  .add(DisplayType.promotion, AppConfig.sourceTypeRate[1])
                  .add(DisplayType.recommend, AppConfig.sourceTypeRate[2])
                  .add(DisplayType.activity, AppConfig.sourceTypeRate[3]).build();

          if(lastPageId==null){
               referId= RandomNum.getRandInt(1,6)+"" ;
          }


          if(pageId== PageId.good_detail  ||pageId== PageId.good_spec||pageId== PageId.comment||pageId== PageId.comment_list){

               sourceType =  sourceTypeGroup.getValue();

               itemType=ItemType.sku_id;
               //item= RandomNum.getRandInt(1, AppConfig.max_sku_id)+"";
               Integer[] skuWeightFemale = AppConfig.skuWeightFemale;
               Integer[] skuWeightMale = AppConfig.skuWeightMale;
               RandomNumBuilder randomNumBuilderF= new RandomNumBuilder(1, 35, skuWeightFemale);
               RandomNumBuilder randomNumBuilderM= new RandomNumBuilder(1, 35, skuWeightMale);

               String tailNum = appCommon.getUid().substring(appCommon.getUid().length() - 1 );
               if(Integer.valueOf(tailNum)%2==1){
                    item=randomNumBuilderM.getNum()+"";
               }else{
                    item=randomNumBuilderF.getNum()+"";
               }
               if(Integer.valueOf(tailNum)%2==0&&Integer.valueOf(item) <20){
                 //   System.out.println(item);
               }

          }else if(pageId== PageId.good_list){
               itemType=ItemType.keyword;
               item=  new RandomBox(AppConfig.searchKeywords).getRandStringValue();
          }else if(pageId== PageId.trade||pageId== PageId.payment||pageId== PageId.payment_done) {
               itemType=ItemType.sku_ids;
               item= RandomNumString.getRandNumString(1, AppConfig.max_sku_id,RandomNum.getRandInt(1,3),",",false);
          }
          return   new AppPage( lastPageId, pageId,itemType,item, duringTime,extend1,extend2,sourceType,referId );

     }


     public static void main(String[] args) {
          String tailNum = "12345".substring("12345".length() - 1 );
          System.out.println(tailNum);
     }



}
